package com.gongj.rabbit.topic;

import com.gongj.rabbit.utils.RabbitMQUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;

/**
 * 动态路由
 */
public class Provider {

    public static void main(String[] args) throws IOException {
        Connection conn = RabbitMQUtil.createConn();

        Channel channel = conn.createChannel();
        String exchangName = "topics";
        channel.exchangeDeclare(exchangName, BuiltinExchangeType.TOPIC);
        String routingKey = "user.email.save";
        channel.basicPublish(exchangName,routingKey,null,("动态路由模式的消息 routing key: ["+routingKey + "]").getBytes());
        RabbitMQUtil.closeConn(channel,conn);
    }
}
